package com.my.thread.pool;

/**
 * Created by ZhongGang
 * at 2018/7/13 10:22
 */
public class RunnableTask<V> implements Task<AsyncResult<V>> {
    private Runnable runnable;
    private AsyncResult<V> asyncResult = null;

    public RunnableTask(Runnable runnable) {
        this.runnable = runnable;
    }

    public RunnableTask(Runnable runnable, AsyncResult<V> asyncResult) {
        this.runnable = runnable;
        this.asyncResult = asyncResult;
    }

    @Override
    public AsyncResult<V> execute() throws Exception {
        this.runnable.run();
        asyncResult.setCompleted(true);
        return this.asyncResult;
    }
}
